<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2018/5/29
 * Time: 20:00
 */

namespace app\model;


class Activity extends Model
{
    public function __construct($db)
    {
        parent::__construct($db, "activity");
        $this->activity="activity";
        $this->activity_host_name="activity_host_name";
        $this->activity_select_person="activity_select_person";
        $this->wangchun_activity="wangchun_activity";
        $this->user_material="user_material";
    }

//////////////////////////////////////////////////////////////////////////////网春大拜年开始///////////////////////////////////////////////////////////////////

    /**
     * 查询所有活动
     */
    public function activity_rukou(){
        $this->db->select("id,activity_big_small,fenlei,huati,activity_pic,online,name");
        $this->db->from($this->activity);
//        $this->db->where(["online"=>2]);
//        $this->db->order_by(["add_time"=>"desc"]);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
//                echo $this->db->last_query();exit;
        return $data["data"];
    }

    /**
     * 查询所有主持人
     */
    public function host(){
        $this->db->select("id,name");
        $this->db->from($this->activity_host_name);
        $this->db->order_by(["add_time"=>"desc"]);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
        //        echo $this->db->last_query();exit;
        return $data["data"];
    }

    /**
     * 查询所有拜年对象
     */
    public function select_person(){
        $this->db->select("id,name");
        $this->db->from($this->activity_select_person);
        $this->db->order_by(["add_time"=>"desc"]);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["data"] = $datas;
        //        echo $this->db->last_query();exit;
        return $data["data"];
    }

    /**
     * 查询单条数据
     */
    public function wangchun_one($where,$select=""){
        if(empty($select)){
            $this->db->select("*");
        }else{
            $this->db->select($select);
        }
        $this->db->from($this->wangchun_activity);
        $this->db->where($where);
        $query =  $this->db->get();
        $datas = $query->one();
        return $datas;
    }

    /**
     * 添加用户素材
     */
    public function add_material($data){
        $this->db->insert($this->user_material,$data);
        return $this->db->insert_id();
    }

    /**
     * 配配配数据
     */
    public function peipeipei($page,$pageSize,$pei_id){
        $this->db->select("a.video_id,a.video_uuid,a.video_big_pic,a.video_small_pic,a.transcode_video_url,a.video_time,a.width,a.height,a.video_desc,a.first_pic1,a.video_share_pic,b.sub_title");
        $this->db->from("video as a");
        $this->db->join("type_sub as b","a.video_join_sub=b.id");
        $this->db->where(["status"=>2,"video_type"=>3,"video_join_sub"=>$pei_id]);
        $total = $this->db->count_all_results();
//        $this->db->order_by(["sorts"=>"desc","add_time"=>"desc"]);
        $this->db->order_by(["add_time"=>"desc"]);
        $this->db->limit($pageSize,($page-1)*$pageSize);
        $query =  $this->db->get();
        $datas = $query->all();
        $data["total"] = $total;
        $data["data"] = $datas;
//        echo $this->db->last_query();exit;
        return $data;
    }

//////////////////////////////////////////////////////////////////////////////网春大拜年结束///////////////////////////////////////////////////////////////////
}